package oneD.models;

import java.util.ArrayList;

import oneD.fem.Constraint;
import oneD.fem.Force;
import oneD.fem.structure.Structure;


public class TensegrityStructure2 extends TensegrityStructureViewer {

	public TensegrityStructure2(String filePath) {
		super(filePath);
	}

	@Override
	protected void manualHandling() {
		Constraint c1 = new Constraint(false, false, false);
//		Constraint c2 = new Constraint(false, false, true);
		int[] groundNode = new int[] { 7, 18, 26, 34, 45, 39, 52, 48, 23, 8,
				19, 59 };
		for (int i = 0; i < groundNode.length; i++)
			struct_.getNode(groundNode[i]).setConstraint(c1);

		Force f = new Force(0, -1e3, 0);
		struct_.getNode(0).setForce(f);
		struct_.getNode(20).setForce(f);
		struct_.getNode(24).setForce(f);

		for (int i = 0; i < struct_.getNumberOfElements(); i++)
			if (elementGroup_.get(i) != 1)
				struct_.getElement(i).setPreStress(1e6);
	}

	public static void setGroupConstraint(Structure struct, Constraint c,
			ArrayList<Integer> elementGroup_) {
		/*
		 * set all the node belongs to all element in elementGroupId with
		 * constraint c
		 */
		for (int i = 0; i < struct.getNumberOfElements(); i++) {
			if (elementGroup_.get(i) == 3)
				struct.getElement(i).getNode(1).setConstraint(c);
		}
	}

	public static void main(String[] args) {

		TensegrityStructure2 model = new TensegrityStructure2(
				"c:/tviewer/v04oct_d.dat");

		model.disableShowElementGroupId();
		model.disableShowElementId();
		model.processUserInput();

		// TensegrityStructureViewer model = new TensegrityStructureViewer(
		// "c:/tviewer/v04oct_d.dat");// "c:/tviewer/x48prism1.dat"
		// fem.structure.Tensegrity struct = model.createStructure();
		//
		// manualHandling(struct, model.getElementGroupId());
		//
		// model.initializeVisualizer(struct);
		// model.disableShowElementId();
		// model.disableShowElementGroupId();
		//
		// /*
		// * draw the plain structure
		// */
		// // model.visualize();
		// // model.enableVisualize();
		//
		// /*
		// * solution for linear static deformation (for reference)
		// */
		// // struct.solve();
		// // model.postVisualize();
		// // model.enableVisualize();
		//
		// /*
		// * solution for nonlinear static deformation
		// */
		// struct.solve(struct.createZeroU());
		// // struct.printResults();
		// model.postVisualize();
		// model.enableVisualize();
		//
		// /*
		// * instability analysis using direct computation
		// */
		// // IVector u = struct.createZeroU();
		// // double lambda = 0;
		// // IVector phi = new ArrayVector(struct.enumerateDOFs());
		// // BLAM.fill(phi, 0.01);
		// // struct.directLoadControlInstabilityComputation(u, lambda, phi);
		//
		// /*
		// * instability analysis using second order theory
		// */
		// // struct.solve();
		// // IVector u = struct.getU();
		// // IVector lambda = null;
		// // struct.secondOrderLoadControlInstabilityComputation(2, u, lambda);

	}

}
